package cn.school.controller.teacher.evaluation;


import cn.school.common.annotation.SysLog;
import cn.school.common.api.CommonPage;
import cn.school.common.api.CommonResult;
import cn.school.common.enums.BusinessType;
import cn.school.teacher.evaluation.entity.TeacherEvaluationScheme;
import cn.school.teacher.evaluation.service.EvaluationSchemeService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@Api(tags = "EvaluationSchemeController => 考评方案管理）")
@RequestMapping("/teacher/evaluation/scheme")
public class EvaluationSchemeController {
    @Autowired
    private EvaluationSchemeService evaluationSchemeService;

    /**
     * @param params 参数内容
     *               pageNum
     *               pageSize
     * @return cn.harry.common.api.CommonPage
     */
    @ApiOperation("list => 获取老师考评方案分页列表")
    @PreAuthorize("@ss.hasPermi('teacher:evaluation:scheme:list')")
    @GetMapping(value = "/list")
    public CommonResult<CommonPage<TeacherEvaluationScheme>> list(@RequestParam Map<String, Object> params) {
        IPage<TeacherEvaluationScheme> page = evaluationSchemeService.getPage(params);
        return CommonResult.success(CommonPage.restPage(page));
    }

    @ApiOperation("info/{id} => 方案信息")
    @PreAuthorize("@ss.hasPermi('teacher:evaluation:scheme:query')")
    @GetMapping("/info/{id}")
    public CommonResult<TeacherEvaluationScheme> info(@PathVariable("id") Long id) {
        TeacherEvaluationScheme entity = this.evaluationSchemeService.getById(id);
        return CommonResult.success(entity);
    }

    @ApiOperation("update/{id} => 修改指定考评方案")
    @PreAuthorize("@ss.hasPermi('teacher:evaluation:scheme:edit')")
    @SysLog(title = "修改指定考评方案", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/update/{id}")
    public CommonResult<Integer> update(@PathVariable("id") Long id, @RequestBody TeacherEvaluationScheme scheme) {
        int count = this.evaluationSchemeService.update(id, scheme);
        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }

    @ApiOperation("create => 新建考评方案")
    @PostMapping(value = "/create")
    @PreAuthorize("@ss.hasPermi('teacher:evaluation:scheme:add')")
    @SysLog(title = "新建考评方案", businessType = BusinessType.INSERT)
    public CommonResult<Integer> create(@RequestBody TeacherEvaluationScheme scheme) {
        int count = this.evaluationSchemeService.create(scheme);
        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }

    @ApiOperation("deleteByIds/{ids} => 删除指定考评方案")
    @PreAuthorize("@ss.hasPermi('teacher:evaluation:scheme:remove')")
    @SysLog(title = "删除指定考评方案", businessType = BusinessType.DELETE)
    @DeleteMapping(value = "/deleteByIds/{ids}")
    public CommonResult<Integer> deleteByIds(@PathVariable Long[] ids) {
        int count = this.evaluationSchemeService.deleteByIds(ids);
        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }
}
